#include "../tools.h"


class Solution {
public:
    ListNode* reverseList(ListNode* head) { // 先动再做，还是先做再动 - 动的操作不一定要在一起
        ListNode *pre = nullptr, *cur = head, *nxt;
        while(cur != nullptr){ // ! 先 nxt = cur->next 顺序很重要
            nxt = cur->next;

            cur->next = pre;
            pre = cur;
            cur = nxt;
        }
        return pre;
    }
};


int main(int argc, char const *argv[])
{
    Solution sol;

    int arr[] = {1,2,3,4,5};
    int size = sizeof(arr) / sizeof(int);

    ListNode* head = create_list(arr, size);
    show(head);

    head = sol.reverseList(head);
    show(head);

    return 0;
}
